package com.coin.exchange.bithumb.api.impl;

import java.util.HashMap;

import org.springframework.stereotype.Service;

import com.coin.exchange.bithumb.Api_Client;
import com.coin.exchange.bithumb.api.BithumbPrivateApi;

/**
 * 
 * @author duyuchong
 *
 */
@Service
public class BithumbPrivateApiImpl implements BithumbPrivateApi {

	@Override
	public String getAccount(String apiKey, String secretKey, String currency) throws Exception {
		HashMap<String, String> params = new HashMap<String, String>();
		params.put("currency", currency);
		return new Api_Client(apiKey, secretKey).callApi("/info/account", params);
	}

	@Override
	public String getBalance(String apiKey, String secretKey, String currency) throws Exception {
		HashMap<String, String> params = new HashMap<String, String>();
		params.put("currency", currency);
		return new Api_Client(apiKey, secretKey).callApi("/info/balance", params);
	}

	@Override
	public String getWalletAddress(String apiKey, String secretKey, String currency) throws Exception {
		HashMap<String, String> params = new HashMap<String, String>();
		params.put("currency", currency);
		return new Api_Client(apiKey, secretKey).callApi("/info/wallet_address", params);
	}

	@Override
	public String getTicker(String apiKey, String secretKey, String order_currency, String payment_currency) throws Exception {
		HashMap<String, String> params = new HashMap<String, String>();
		params.put("order_currency", order_currency);
		params.put("payment_currency", payment_currency);
		return new Api_Client(apiKey, secretKey).callApi("/info/ticker", params);
	}

	@Override
	public String getOrders(String apiKey, String secretKey, String order_id, String type, Integer count, Long after, String currency) throws Exception {
		HashMap<String, String> params = new HashMap<String, String>();
		params.put("order_id", order_id);
		params.put("type", type);
		params.put("count", count.toString());
		params.put("after", after.toString());
		params.put("currency", currency);
		return new Api_Client(apiKey, secretKey).callApi("/info/orders", params);
	}

	@Override
	public String getUserTransactions(String apiKey, String secretKey, Integer offset, Integer count, Integer searchGb, String currency) throws Exception {
		HashMap<String, String> params = new HashMap<String, String>();
		params.put("offset", offset.toString());
		params.put("count", count.toString());
		params.put("searchGb", searchGb.toString());
		params.put("currency", currency);
		return new Api_Client(apiKey, secretKey).callApi("/info/user_transactions", params);
	}

	@Override
	public String getOrderDetail(String apiKey, String secretKey, String order_id, String type, String currency) throws Exception {
		HashMap<String, String> params = new HashMap<String, String>();
		params.put("order_id", order_id);
		params.put("type", type);
		params.put("currency", currency);
		return new Api_Client(apiKey, secretKey).callApi("/info/order_detail", params);
	}

	@Override
	public String place(String apiKey, String secretKey, String order_currency, String payment_currency, Float units, Integer price, String type) throws Exception {
		HashMap<String, String> params = new HashMap<String, String>();
		params.put("order_currency", order_currency);
		params.put("payment_currency", payment_currency);
		params.put("units", units.toString());
		params.put("price", price.toString());
		params.put("type", type);
		return new Api_Client(apiKey, secretKey).callApi("/trade/place", params);
	}

	@Override
	public String cancel(String apiKey, String secretKey, String type, String order_id, String currency) throws Exception {
		HashMap<String, String> params = new HashMap<String, String>();
		params.put("order_id", order_id);
		params.put("type", type);
		params.put("currency", currency);
		return new Api_Client(apiKey, secretKey).callApi("/trade/cancel", params);
	}

	@Override
	public String marketBuy(String apiKey, String secretKey, Float units, String currency) throws Exception {
		HashMap<String, String> params = new HashMap<String, String>();
		params.put("units", units.toString());
		params.put("currency", currency);
		return new Api_Client(apiKey, secretKey).callApi("/trade/market_buy", params);
	}

	@Override
	public String marketSell(String apiKey, String secretKey, Float units, String currency) throws Exception {
		HashMap<String, String> params = new HashMap<String, String>();
		params.put("units", units.toString());
		params.put("currency", currency);
		return new Api_Client(apiKey, secretKey).callApi("/trade/market_sell", params);
	}

}
